<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0 , maximum-scale=1.0"/>
		<title></title>
	</head>
	<body>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
		<p></p>
	</body>
	<script type="text/javascript">
		var msg = document.querySelectorAll("p");
		if(window.DeviceMotionEvent){
			window.addEventListener("devicemotion",callback,false)
		}else{
			alert("呵呵")
		}
		function callback(event){
			//获取设备的每个方向的加速度（不考虑重力加速度）
			var aX = Math.ceil(event.acceleration.x);
			var aY = Math.ceil(event.acceleration.y);
			var aZ = Math.ceil(event.acceleration.z);
			//获取设备的每个方向的加速度（考虑重力加速度）
			var aGX = Math.ceil(event.accelerationIncludingGravity.x);
			var aGY = Math.ceil(event.accelerationIncludingGravity.y);
			var aGZ = Math.ceil(event.accelerationIncludingGravity.z);
			//获取事件之间的时间间隔
			var time = event.interval;
			//表示设备方向
			var alpha = Math.ceil(event.rotationRate.alpha);
			var beta = Math.ceil(event.rotationRate.beta);
			var gamma = Math.ceil(event.rotationRate.gamma);
			msg[0].innerHTML = "aX:" + aX + "<br/>";
			msg[1].innerHTML = "aY:" + aY + "<br/>";
			msg[2].innerHTML = "aZ:" + aZ + "<br/>";
			msg[3].innerHTML = "aGX:" + aGX + "<br/>";
			msg[4].innerHTML = "aGY:" + aGY + "<br/>";
			msg[5].innerHTML = "aGZ:" + aGZ + "<br/>";
			msg[6].innerHTML = "time:" + time + "<br/>";
			msg[7].innerHTML = "alpha:" + alpha;
			msg[8].innerHTML = "beta:" + beta;
			msg[9].innerHTML = "gamma:" + gamma;
		}
		
		
	</script>
</html>
